<?php
/* 
 *入库详情
 */
class Enter_detailAction extends TransDetailAction {
    public function _filter(&$map) {
        $key = trim($_REQUEST['keywords']);
        if(!empty($key)) {
            $map['name'] = array('like',"%".$key."%");//产品名称
            $map['enter_no'] = array('like',"%".$key."%");
            $map['tm'] = array('like',"%".$key."%");//条码
            /* exact filter
            $map['Warehouse.name'] = array('like',"%".$key."%");//仓库
            $map['Customer.name'] = array('like',"%".$key."%");//customer
            $map['number'] = array('eq',$key);
            //$map['minstock'] = array('like',"%".$key."%");*/
            $map['_logic'] = "or";
        }
        if(!empty($_REQUEST['enter_id'])){
           $map['enter_id'] = $_REQUEST['enter_id'];
        }
    }
    public function _before_index(){
        $this->assign('suppliers',M('Supplier')->where('status = 1')->field('id,name')->findAll());
        $this->assign('users',M('User')->where('status = 1')->field('id,name')->findAll());
    }

    public function index(){
        parent::index('EnterView');
    }

    public function _before_add() {
        $supplier = M('Supplier')->where('status=1')->field('id,name')->findAll();
        $this->assign('supplier',$supplier);
    }

    public function  _before_insert() {
        $_POST['product_id'] = empty ($_POST['ptm_id'])?(
                $_POST['product_id'] = empty ($_POST['ppy_id'])? 
                ($_POST['product_id'] = empty ($_POST['hz_id'])? 0:$_POST['hz_id'])
                    : $_POST['ppy_id'] ) : $_POST['ptm_id'];

        if($_POST['number'] < 1)
            $this->error("产品入库数量必须大于1");
        if(empty($_POST['enter_id']) )
            $this->error("必须选择入库单号");
    }
}
?>
